#! /usr/bin/env python
import math
import sys

LIMIT=3000

def solv(a,b,c):
#    print a,b,c
    x = b*b-4*a*c
    if x<0:
        return None
    x = math.sqrt(x)
    if x > int(x):
        return None
    x = int(x)
    #b == -1, we skip this check
    #if x <=b:
    #    return None
    if (x-b)%(2*a)>0:
        return None
    return (x-b)/a/2

def solv1(c):
    if not (math.sqrt(1+24*c)+1)%6:
        return (int(math.sqrt(1+24*c)+1))/6
    return None
def pent(n):
    return n*(3*n-1)/2

def main():
    for i in range(1,LIMIT):
        for j in range(i+1,i+LIMIT):
            k = solv1(i*(3*i-1)/2 + j*(3*j-1)/2)
            if i==1020 and j==1147:
                print k
            if k:
#                print i,j,k
#                print pent(i),pent(j),pent(k),pent(i)+pent(j)
#                1/0
                l = solv1(j*(3*j-1)/2 + k*(3*k-1)/2)
                if l:
                    print i,j,k,l
                    print pent(i),pent(j),pent(k),pent(l)
                    1/0
                l = solv1(i*(3*i-1)/2 + k*(3*k-1)/2)
                if l:
                    print j,i,k,l
                    print pent(j),pent(i),pent(k),pent(l)
                    1/0

def main1():
    global LIMIT
    if len(sys.argv)>1:
        LIMIT = int(sys.argv[1])
    for i in range(3,LIMIT):
        for j in range(1,i):
            k = solv1(i*(3*i-1)/2 + j*(3*j-1)/2)
            if k:
                print i,j,k
#                print pent(i),pent(j),pent(k),pent(i)+pent(j)
#                1/0
                l = solv1(i*(3*i-1)/2 + k*(3*k-1)/2)
                if l:
                    print j,i,k,l
                    print pent(j),pent(i),pent(k),pent(l)
                    1/0
            
if __name__=='__main__':
    main()
